{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.7.1\n",
      "输入quit 表示选手成绩录入完毕\n",
      "第1名: 2,成绩为99.0分\n",
      "第2名: 5,成绩为96.0分\n",
      "第3名: 1,成绩为88.0分\n",
      "第4名: 4,成绩为77.0分\n",
      "第5名: 3,成绩为66.0分\n"
     ]
    }
   ],
   "source": [
    "print('5.7.1')\n",
    "player_info = {}\n",
    "li = []\n",
    "print('输入quit 表示选手成绩录入完毕')\n",
    "while True:\n",
    "    name = input(\"请输入选手名称：\\n\")\n",
    "    if name == 'quit':\n",
    "        break\n",
    "    score = float(input(\"请输入选手票数：\\n\"))\n",
    "    player_info[name] = score\n",
    "items = player_info.items ()\n",
    "for j in items:\n",
    "    li.append([j[1], j[0]])\n",
    "li.sort()\n",
    "count = len(li) - 1\n",
    "for i in range (1, len (li) + 1):\n",
    "    print(f\"第{i}名: {li[count][1]},成绩为{li[count][0]}分\")\n",
    "    count -= 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.7.2\n",
      "====================\n",
      "欢迎使用通讯录：\n",
      "1.添加联系人\n",
      "2.查看通讯录\n",
      "3.删除联系人\n",
      "4.修改联系人信息\n",
      "5.查找联系人\n",
      "6.退出\n",
      "====================\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "通讯录无信息\n",
      "通讯录无信息\n",
      "通讯录无信息\n"
     ]
    }
   ],
   "source": [
    "print('5.7.2')\n",
    "person_info = []\n",
    "print(\"=\" * 20)\n",
    "print('欢迎使用通讯录：')\n",
    "print(\"1.添加联系人\")\n",
    "print(\"2.查看通讯录\")\n",
    "print(\"3.删除联系人\")\n",
    "print(\"4.修改联系人信息\")\n",
    "print(\"5.查找联系人\")\n",
    "print(\"6.退出\")\n",
    "print (\"=\" * 20)\n",
    "while True:\n",
    "    per_dict = {}\n",
    "    fun_num = input('请输入功能序号：')\n",
    "    if fun_num == '1':\n",
    "        per_name = input('请输入联系人的姓名：')\n",
    "        phone_num = input('请输入联系人的手机号：')\n",
    "        per_email = input('请输入联系人的邮箱：')\n",
    "        per_address = input('请输入联系人的地址：')\n",
    "        if per_name.strip() == '':\n",
    "            print('请输入正确信息')\n",
    "            continue\n",
    "        else:\n",
    "            per_dict.update({'姓名': per_name,\n",
    "                             '手机号': phone_num,\n",
    "                             '电子邮箱': per_email,\n",
    "                             '联系地址': per_address})\n",
    "            person_info.append(per_dict)\n",
    "            print('保存成功')\n",
    "    elif fun_num == '2':\n",
    "        if len(person_info) == 0:\n",
    "            print('通讯录无信息')\n",
    "        for i in person_info:\n",
    "            for title, info in i.items() :\n",
    "                print (title + ':' + info)\n",
    "    elif fun_num == '3':\n",
    "        if len(person_info) != 0:\n",
    "            del_name = input('请输入要删除的联系人姓名：')\n",
    "            for i in person_info:\n",
    "                if  del_name in i.values() :\n",
    "                    person_info.remove(i)\n",
    "                    print (person_info)\n",
    "                    print('删除成功')\n",
    "                else:\n",
    "                    print('该联系人不在通讯录中')\n",
    "        else:\n",
    "            print('通讯录无信息')\n",
    "    elif fun_num == '4': \n",
    "        if len (person_info) != 0:\n",
    "            modi_info = input('请输入要修改联系人姓名：')\n",
    "            for i in person_info:\n",
    "                if modi_info in i. values () :\n",
    "                    index_num = person_info. index (i)\n",
    "                    dict_cur_perinfo = person_info[index_num]\n",
    "                    for title, info in dict_cur_perinfo. items () :\n",
    "                        print (title + ':' + info)\n",
    "                    modi_name = input('请输入新的姓名：')\n",
    "                    modi_phone = input('请输入新的手机号：')\n",
    "                    modi_email = input('请输入新的邮箱：')\n",
    "                    modi_address = input('请输入新的地址: ')\n",
    "                    dict_cur_perinfo.update(姓名= modi_name)\n",
    "                    dict_cur_perinfo.update(手机号= modi_phone)\n",
    "                    dict_cur_perinfo.update(电子邮箱= modi_email)\n",
    "                    dict_cur_perinfo.update(联系地址= modi_address)\n",
    "                    print (person_info)\n",
    "                else:\n",
    "                    print('通讯录无信息')\n",
    "    elif fun_num == '5':\n",
    "        if len(person_info) != 0:\n",
    "            query_name = input('请输入要查找的联系人姓名：')\n",
    "            for i in person_info:\n",
    "                if query_name in i.values() :\n",
    "                    index_num = person_info.index(i)\n",
    "                    for title, info in person_info [index_num].items() :\n",
    "                       print (title + ':' + info)\n",
    "                    break\n",
    "                else:\n",
    "                     print('该联系人不在通讯录中')\n",
    "        else:\n",
    "            print('通讯录无信息')\n",
    "    elif fun_num == '6':\n",
    "        break\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
